<!-- dict表单弹窗 -->
<form id="dict-form" lay-filter="dict-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">数据值<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input name="value" placeholder="数据值" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标签名<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input name="label" placeholder="标签名" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input name="type" placeholder="类型" type="text" class="layui-input" lay-verify="required"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input name="description" placeholder="描述" type="text" class="layui-input"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input name="sort" placeholder="请输入排序号" type="number" class="layui-input"/>
        </div>
    </div>

    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" app-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="dict-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects', 'jquery'], function () {
        const $ = layui.jquery;
        const layer = layui.layer;
        const admin = layui.admin;
        const form = layui.form;

        let url = basePath + 'system/dict/add';
        // 回显dict数据
        const dict = admin.getTempData('t_dict');
        if (dict) {
            url = basePath + 'system/dict/update';
            form.val('dict-form', dict);
        }
        // 表单提交事件
        form.on('submit(dict-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.success) {
                    layer.msg(data.msg, {icon: 1});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        });
    });
</script>